<style>
    .panel {
        color: #333;
        padding: 6px;
        border: 1px solid silver;
        box-shadow: 3px 4px 3px 0px silver;
        position: absolute;
        background-color: #eee;
        top: 10px;
        right: 10px;
        border-radius: 5px;
        overflow: hidden;
        line-height: 20px;
    }

    .panel .address {
        width: 250px;
        height: 25px;
    }
</style>
<section class="content">
    <div class="row addsullier">
        <div class="col-md-12">
            <div class="box box-danger">
                <div class="box-body ">
                    <div id="container" style="width: 100%;height: 400px;"></div>
                    <div class='panel'>
                        输入地址查询位置:</br>
                        <input id='input' value='{$address}' class="address"/>
                        <div id='message'></div>
                    </div>
                    <div style="margin-top: 10px">
                        <input id="curlonlat" style="display:inline;width: 30%"
                               value="" type="hidden"/>
                        <input id="caddress" style="display:inline;width: 60%"
                               value="" type="hidden"/>
                    </div>
                    <div style="clear: both;"></div>
                    <div class="box-footer">
                           <span class="input-group-btn">
                                <button class="btn btn-primary pull-right" type="button" id='form_submit2'>提交</button>
                            </span>
                    </div>
                </div>
            </div>
        </div>
    </div>

    <script type="text/javascript">
        var icon, marker, geocoder, infoWindow;
        var lng = '{$lng}', lat = '{$lat}', address = '{$address}';
        $(function () {
            setTimeout(function () {
                var centerPoint = null;
                if (lng != "0" || lat != "0") {
                    centerPoint = new BMap.Point(lng, lat);  // 创建点坐标
                } else {
                    centerPoint = new BMap.Point(112.99935279, 28.21547823);  // 创建点坐标
                }
                var t = 0;
                $('.address').keyup(function () {
                    clearTimeout(t);
                    t = setTimeout(function () {
                        var adr = $('.address').val();
                        searchAddrss(adr);
                    }, 500);
                });
                infoWindow = new BMap.InfoWindow("", {
                    offset: new BMap.Size(0, -34)
                });  // 创建信息窗口对象
                infoWindow.disableCloseOnClick();
                map = new BMap.Map("container");
                map.enableScrollWheelZoom();
                map.centerAndZoom(centerPoint, 15);
                var myIcon = new BMap.Icon('__PUBLIC__/images/main_index_checkin_pressed.png', new BMap.Size(48, 48), {
                    'imageSize': new BMap.Size(38, 38),
                    'anchor': new BMap.Size(17, 34)
                });
                marker = new BMap.Marker(centerPoint, {icon: myIcon});// 创建标注
                map.addOverlay(marker);             // 将标注添加到地图中
                marker.enableDragging();
                geocoder = new BMap.Geocoder();
                var pt = marker.getPosition();
                geocoder.getLocation(pt, function (rs) {
//                        var addComp = rs.addressComponents;
                    $('#curlonlat').val(pt.lng + "," + pt.lat);
                    $("#caddress").val(rs.address);
                    openInfo('经纬度:' + pt.lng + "," + pt.lat + "<br/>地址:" + rs.address, pt);
                });
                marker.addEventListener("dragend", function () {
                    var pt = marker.getPosition();
//                    alert("地图中心点变更为：" + center.lng + ", " + center.lat);
                    geocoder.getLocation(pt, function (rs) {
//                        var addComp = rs.addressComponents;
                        $('#curlonlat').val(pt.lng + "," + pt.lat);
                        $("#caddress").val(rs.address);
                        openInfo('经纬度:' + pt.lng + "," + pt.lat + "<br/>地址:" + rs.address, pt);
                    });
                });

                marker.addEventListener("dragging", function () {
                    if (infoWindow.isOpen()) {
                        infoWindow.close();
                    }
                });

                if (address != "" && lng == "0" && lat == "0") {
                    searchAddrss(address);
                }
            }, 200);
        });

        function searchAddrss(address) {
            geocoder.getPoint(address, function (point) {
                if (point) {
                    map.centerAndZoom(point, 15);
                    marker.setPosition(point);
                    openInfo('经纬度:' + point.lng + "," + point.lat + "<br/>地址:" + address, point);
                } else {
                    openInfo('获取位置失败,请在地图上拖动标记点定位,或修改地址', marker.getPosition());
                }
            }, '长沙市');
        }

        $('#form_submit2').click(function () {
            $("#task_end").val($("#caddress").val());
            $("#task_end_latgong").val($("#curlonlat").val());
            dialog.get('getLonlat').close().remove();
        });

        //构建信息窗体中显示的内容
        function openInfo(msg, point) {
            //构建信息窗体中显示的内容

            infoWindow.setContent(msg);  // 创建信息窗口对象
            var centerPoint = new BMap.Point(point.lng, point.lat);  // 创建点坐标
            map.openInfoWindow(infoWindow, centerPoint); //开启信息窗口
        }
    </script>
</section>

